package com.studentstreet.component;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.studentstreet.R;

/**
 * @author likebamboo
 * 
 */
public class LoadStateView extends RelativeLayout {

	ProgressBar progBar;

	LinearLayout downLoadErrMsgBox;

	TextView downLoadErrText;

	Button btnListLoadErr;

	public LoadStateView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	@Override
	protected void onFinishInflate() {
		super.onFinishInflate();
		progBar = (ProgressBar) findViewById(R.id.progBar);
		downLoadErrMsgBox = (LinearLayout) findViewById(R.id.downLoadErrMsgBox);
		downLoadErrText = (TextView) findViewById(R.id.downLoadErrText);
		btnListLoadErr = (Button) findViewById(R.id.btnListLoadErr);
	}

	// 开始加载
	public void startLoad() {
		setBackgroundDrawable(getResources().getDrawable(R.drawable.bg));
		downLoadErrMsgBox.setVisibility(View.GONE);
		progBar.setVisibility(View.VISIBLE);
	}

	// 加载完成
	public void stopLoad() {
		setBackgroundColor(Color.TRANSPARENT);
		progBar.setVisibility(View.GONE);
	}

	// 加载失败
	public void showError() {
		setBackgroundDrawable(getResources().getDrawable(R.drawable.bg));
		downLoadErrMsgBox.setVisibility(View.VISIBLE);
		progBar.setVisibility(View.GONE);
	}

	// 加载后内容任为空
	public void showEmpty() {
		setBackgroundDrawable(getResources().getDrawable(R.drawable.bg));
		downLoadErrMsgBox.setVisibility(View.VISIBLE);
		downLoadErrText
				.setText(getResources().getString(R.string.list_no_item));
		downLoadErrText.setVisibility(View.VISIBLE);
		btnListLoadErr.setVisibility(View.GONE);
		progBar.setVisibility(View.GONE);
	}

	// 加载后内容任为空
	public void showEmpty(CharSequence text) {
		setBackgroundDrawable(getResources().getDrawable(R.drawable.bg));
		downLoadErrMsgBox.setVisibility(View.VISIBLE);
		downLoadErrText.setText(text);
		downLoadErrText.setVisibility(View.VISIBLE);
		btnListLoadErr.setVisibility(View.GONE);
		progBar.setVisibility(View.GONE);
	}

	public void setOnReloadClickListener(OnClickListener onReloadClickListener) {
		btnListLoadErr.setOnClickListener(onReloadClickListener);
	}
}
